package com.fzz.learnitservice.controller;

import com.commonfzz.pojo.po.R;
import com.fzz.learnitservice.pojo.dto.WordTranslateDTO;
import com.fzz.learnitservice.service.IWordImportService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


@Slf4j
@RestController
@RequestMapping("/wordHandle")
@RequiredArgsConstructor
@Validated
public class WordHandleController {


    private final IWordImportService wordImportService;

    /**
     * 从资源读取文件，导入所有单词数据
     */
    @PostMapping("/importAll")
    public R<Map<String, Object>> importAllWords() {
        return R.ok(wordImportService.importAllWordsWithStats());
    }

    /**
     * 中英互译
     * @param wordTranslateDTO
     * @return
     */
    @PostMapping("/translate")
    public R<String> translate(@Valid @RequestBody WordTranslateDTO wordTranslateDTO) {
        return R.ok(wordImportService.translate(wordTranslateDTO));
    }
}

